<?php

class AutosettingController extends MyClass_Action {
	protected $controller;
	protected $action;
	protected $_user;
	
	public function init() {
		
		$this->commonAction();	
	
	}
	//用户首页
	public function indexAction() {
		try {
			// $this->view->datenow=date('Y-m-d H:i:s');
 
			//未处理反馈
			$sql="SELECT count(*) as num  FROM `feedback` where  isdelete=0 and isover=0";
			$feedbacknum=$this->_dbAdapter ->fetchOne( $sql );
			
			//断网客户服务器
			$outdatetime=time()-900;
			$sql="SELECT max(lasttime)  from clients group by groupid,schoolid";
			$clientidlist=$this->_dbAdapter ->fetchCol ( $sql );
			$outdatetimelist=array();
			if($clientidlist){
				foreach($clientidlist as $key => $value ){
					if(strtotime($value)<$outdatetime){
						$outdatetimelist[]=$value;
					}
				}
			}
			//echo count($outdatetimelist);
			$outdatetimenum=count($outdatetimelist);
			
			
			//伊顿未审核图片数据
			$groupid=1;
			$sql="SELECT * FROM `groups` where groupid=".$groupid;
			$result = $this->_dbAdapter->fetchRow ($sql);
/*			$dbArray=array();
			$dbArray['host']=$result['dbhost'];
			$dbArray['username']=$result['dbusername'];
			$dbArray['password']=$this->authcode($result['dbpassword'], 'DECODE', 'mactop') ;
			$dbArray['dbname']=$result['dbname'];
			$groupdbAdapter = Zend_Db::factory ("PDO_MYSQL", $dbArray );
*/
			$sql='select count(case when ischecked=0 then "nochecked" end) nochecked,count(case when ischecked=1 then "nochecked" end) nopublish from article_files_class_v where groupid='.$groupid.' and isdelete=0 and mark=0 and articlekey=""';
			$result=$groupdbAdapter->fetchRow($sql);
			$article_nochecked=$result['nochecked'];
			$article_nopublish=$result['nopublish'];
			
			//$this->view->groupid=$groupid;
            //  print_r($this->_dbAdapter);  exit;
			
			//未处理私信
			//查找给运维发消息的班级uid，班级id是唯一的
            $sql = "select DISTINCT(from_uid) as cid from letter where isdelete=0 and to_role='admin' and from_role='teacher'";	
			$cids = $this->_dbAdapter->fetchAll($sql);
			//print_r($cids);echo '<br />';
			//获得该班级的最后一条私信
			$letternum=0;
			foreach($cids as $cid){
			    //如果运维是回复的最后一条，则该记录被忽略,只显示老师为最后一条的信息
				$sql = "select from_role as role from letter where (to_role='teacher' and to_uid=".$cid['cid'].") or(from_role='teacher' and from_uid='".$cid['cid']."') order by addtime desc limit 1";
				$one = $this->_dbAdapter->fetchOne($sql);
				if($one=='teacher'){
					$letternum=$letternum+1;
				}
			}
			
			//未处理共享文件
			$publicfilenum = $this->_dbAdapter->fetchOne ( "select count(*) from samba_files where isdelete=0 and isignore=0 and isover=0" );			
			
			$arr=array(
			      'value'=>$feedbacknum.','.$outdatetimenum.','.$article_nochecked.','.$article_nopublish.','.$letternum.','.$publicfilenum
			    ); 
			  
			 $res=$this->_dbAdapter ->update ('setting',$arr,'variable="indexvariable"');
			 if($res){
				 echo "chenggong ";  exit;
			  }else{
				 echo "shibai"; exit;
			  }
			
		} catch ( Exception $e ) {
			$this->feedback ( $e->getMessage (), '注意', 'javascript:window.history.back();', 'warning' );
		}
	}

	 
	 //以下内容保持不变
	public function noRouteAction() {
		$this->_redirect ( '/' );
	}
	
	public function __call($method, $args) {
		if ('Action' == substr ( $method, - 6 )) {
			$url = '/' . $this->controller . '/index';
			return $this->_redirect ( $url );
		}
		throw new Exception ( 'Invalid method' );
	}
}

